<template>
    <div class="home-icons">
      <swiper dots-class="custom-bottom" dots-position="center" >
        <swiper-item class="swiper-img"  v-for="(items, index) in pages" :key="index">
          <div class="icon-item" v-for="items in items" :key="items.id">
            <div class="icon-img">
              <img class="icon-img-content" :src="items.imgUrl" alt="">
            </div>
            <div class="icon-desc">{{items.desc}}</div>
          </div>
        </swiper-item>
      </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
    }
  },
  props: {
    IconData: {
      type: Array
    }
  },
  mounted () {
  },
  computed: {
    pages () {
      const pages = []
      // 将一位数组转换为二维数组 再将对应子元素放入二维数组中
      this.IconData.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/global.styl';
  @import '~styles/mixin.styl';
  .home-icons >>> .vux-indicator
    bottom: 0px
  .home-icons >>> .active
    background-color: $bgColor !important
  .home-icons
    padding-top: .1rem
    background: #fff
    .icon-item
      position: relative
      width: 25%
      height: 0
      float: left
      overflow: hidden
      padding-bottom: 22%
      .icon-img
        position: absolute
        top: 0
        left: 0
        right: 0
        bottom: .4rem
        box-sizing: border-box
        padding: .1rem
        .icon-img-content
          display: block
          margin: 0 auto
          height: 100%
      .icon-desc
        position: absolute
        bottom:0
        left:0
        right:0
        text-align: center
        font-size: .28rem
        height: .48rem
        line-height: .48rem
        ellipsis()
</style>
